clear all; close all;

N = 128;
M = 48;

% 构造正交矩阵B, 使f在基B上是稀疏的, 稀疏信号为X
 R = rand(N);
 B = orth(R);

% B  = zeros(N,N);
% for i = 1 : N
%     for j = 1 : N
%         B(i,j) = sqrt(1/N)*exp(-1j*2*pi/N*((i-1)*(j-1)));
%     end
% end
% B = B';

% sensing matrix
psi = rand(M, N);

X = zeros(N,1);
X(70) = 10; X(11) =  12; X(100) = 2;

f = B * X;
y = psi * f;
A = psi * B;

% xhat 表示稀疏信号X经过正交矩阵B变换得到的f, 由f通过mp恢复出的稀疏信号X
[xhat, u] = omp(B, f, 3);

% xhathat 表示稀疏信号X经过观测矩阵psi观测到的样值y, 由y通过mp恢复出的稀疏信号X
[xhathat, ~] = omp(A, y, 4);

%torr = 1e-3;
%cvx_begin
%    variable xhathat(N);
%    minimize( norm(xhathat,1) );
%    subject to
%        norm(A * xhathat - y, 2)< torr;
%cvx_end

figure; hold on;
plot(X,'rx');
plot(xhat,'b+');
plot(xhathat,'go');